//
//  JWTStoreComboBoxViewController.m
//  JWT
//
//  Created by ndm on 17/2/6.
//  Copyright © 2017年 com.jwtsoft. All rights reserved.
//

#import "JWTStoreComboBoxViewController.h"
#import "JWTNavTitleView.h"
#import "JWTSlideSwitchView.h"

#import "QCListViewController.h"
#import "JWTCalendar.h"
#import "JWTSelectCourseSwipeView.h"

@interface JWTStoreComboBoxViewController()<QCSlideSwitchViewDelegate,UIGestureRecognizerDelegate>

@property (nonatomic,strong) JWTNavTitleView *navTitleView;

@property (nonatomic,strong) JWTSelectCourseSwipeView *selCourseSwipeView;

@property (nonatomic, strong) JWTSlideSwitchView *slideSwitchView;
@property (nonatomic, strong) QCListViewController *vc1;
@property (nonatomic, strong) QCListViewController *vc2;
@property (nonatomic, strong) QCListViewController *vc3;
@property (nonatomic, strong) QCListViewController *vc4;
@property (nonatomic, strong) QCListViewController *vc5;
@property (nonatomic, strong) QCListViewController *vc6;
@property (nonatomic, strong) QCListViewController *vc7;



@end

@implementation JWTStoreComboBoxViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTitleView];
    
    [self initSlideView];
    
    [self initSwipeSelectCourseView];
}

-(void) initTitleView{
    _navTitleView = [JWTNavTitleView sharedInstance];
    self.navigationItem.titleView = _navTitleView;
}

-(void) initSwipeSelectCourseView{
    _selCourseSwipeView = [[JWTSelectCourseSwipeView alloc] initWithFrame:CGRectMake(-(UISCREEN_WIDTH*0.95), 0, UISCREEN_WIDTH, UISCREEN_HEIGHT)];
    
    UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
    [mainWindow addSubview:_selCourseSwipeView];
    
    WS(weakSelf);
    _selCourseSwipeView.getAreaInfo =^(NSString *storeID,NSString *storeName){
        weakSelf.vc1.storeID = storeID;
        weakSelf.vc2.storeID = storeID;
        weakSelf.vc3.storeID = storeID;
        weakSelf.vc4.storeID = storeID;
        weakSelf.vc5.storeID = storeID;
        weakSelf.vc6.storeID = storeID;
        weakSelf.vc7.storeID = storeID;
        
        NSString *courName;
        if ([APPDELEGATE.courseType isEqualToString:@"1"]) {
            courName = @"成人课";
        }else if ([APPDELEGATE.courseType isEqualToString:@"2"]){
            courName = @"儿童课";
        }else if ([APPDELEGATE.courseType isEqualToString:@"3"]){
            courName = @"兴趣课";
        }
        weakSelf.navTitleView.navTitleLabel.text = [NSString stringWithFormat:@"%@ | %@",(storeName == nil?@"":storeName),courName];
        
    };
    
    _selCourseSwipeView.getCourseInfo = ^ (NSString *courseType){
        weakSelf.vc1.courseType = courseType;
        weakSelf.vc2.courseType = courseType;
        weakSelf.vc3.courseType = courseType;
        weakSelf.vc4.courseType = courseType;
        weakSelf.vc5.courseType = courseType;
        weakSelf.vc6.courseType = courseType;
        weakSelf.vc7.courseType = courseType;
        
        NSString *courName;
        if ([APPDELEGATE.courseType isEqualToString:@"1"]) {
            courName = @"成人课";
        }else if ([APPDELEGATE.courseType isEqualToString:@"2"]){
            courName = @"儿童课";
        }else if ([APPDELEGATE.courseType isEqualToString:@"3"]){
            courName = @"兴趣课";
        }
        weakSelf.navTitleView.navTitleLabel.text = [NSString stringWithFormat:@"%@ | %@",(APPDELEGATE.storeName == nil?@"":APPDELEGATE.storeName),courName];
    };
}



-(void)viewDidAppear:(BOOL)animated{
    self.navigationController.interactivePopGestureRecognizer.enabled = NO; //这句话的意思是， 支持左边滑动后退
    _selCourseSwipeView.swipeView.userInteractionEnabled = YES;
}

-(void)viewWillDisappear:(BOOL)animated{
    [HUD hideUIBlockingIndicator];
    [_navTitleView removeSubView];
    _selCourseSwipeView.swipeView.userInteractionEnabled = NO;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES; //这句话的意思是， 支持左边滑动后退
}



-(void) initSlideView{
    APPDELEGATE.courseType = _type;
    
    _slideSwitchView= [[JWTSlideSwitchView alloc ] initWithFrame: CGRectMake(self.view.left, self.view.top, UISCREEN_WIDTH, UISCREEN_HEIGHT-64)];
    _slideSwitchView.slideSwitchViewDelegate = self;
    [self.view addSubview:_slideSwitchView];
    
    self.slideSwitchView.tabItemNormalColor = [JWTSlideSwitchView colorFromHexRGB:@"868686"];
    self.slideSwitchView.tabItemSelectedColor = [JWTSlideSwitchView colorFromHexRGB:@"bb0b15"];
    self.slideSwitchView.shadowImage = [[UIImage imageNamed:@"red_line_and_shadow"] stretchableImageWithLeftCapWidth:59.0f topCapHeight:0.0f];
    
    NSArray *calendarArray = [[JWTCalendar sharedInstance] calendarFromDate];
    
    self.vc1 = [[QCListViewController alloc] init];
    self.vc1.title = calendarArray[0];
    
    self.vc2 = [[QCListViewController alloc] init];
    self.vc2.title = calendarArray[1];
    
    self.vc3 = [[QCListViewController alloc] init];
    self.vc3.title = calendarArray[2];
    
    self.vc4 = [[QCListViewController alloc] init];
    self.vc4.title = calendarArray[3];
    
    self.vc5 = [[QCListViewController alloc] init];
    self.vc5.title = calendarArray[4];
    
    self.vc6 = [[QCListViewController alloc] init];
    self.vc6.title = calendarArray[5];
    
    self.vc7 = [[QCListViewController alloc] init];
    self.vc7.title = calendarArray[6];
    
    //    UIButton *rightSideButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //    [rightSideButton setImage:[UIImage imageNamed:@"icon_rightarrow.png"] forState:UIControlStateNormal];
    //    [rightSideButton setImage:[UIImage imageNamed:@"icon_rightarrow.png"]  forState:UIControlStateHighlighted];
    //    rightSideButton.frame = CGRectMake(0, 0, 20.0f, 44.0f);
    //    rightSideButton.userInteractionEnabled = NO;
    //    self.slideSwitchView.rigthSideButton = rightSideButton;
    
    [self.slideSwitchView buildUI];
}


#pragma mark - 滑动tab视图代理方法


- (NSUInteger)numberOfTab:(JWTSlideSwitchView *)view
{
    // you can set the best you can do it ;
    return 7;
}

- (UIViewController *)slideSwitchView:(JWTSlideSwitchView *)view viewOfTab:(NSUInteger)number
{
    if (number == 0) {
        return self.vc1;
    } else if (number == 1) {
        return self.vc2;
    } else if (number == 2) {
        return self.vc3;
    } else if (number == 3) {
        return self.vc4;
    } else if (number == 4) {
        return self.vc5;
    } else if (number == 5) {
        return self.vc6;
    } else if (number == 6) {
        return self.vc7;
    } else {
        return nil;
    }
}

//- (void)slideSwitchView:(QCSlideSwitchView *)view panLeftEdge:(UIPanGestureRecognizer *)panParam
//{
//    QCViewController *drawerController = (QCViewController *)self.navigationController.mm_drawerController;
//    [drawerController panGestureCallback:panParam];
//}

- (void)slideSwitchView:(JWTSlideSwitchView *)view didselectTab:(NSUInteger)number
{
    QCListViewController *vc = nil;
    [vc.listArray removeAllObjects];
    [vc.tableViewList reloadData];
    if (number == 0) {
        vc = self.vc1;
    } else if (number == 1) {
        vc = self.vc2;
    } else if (number == 2) {
        vc = self.vc3;
    } else if (number == 3) {
        vc = self.vc4;
    } else if (number == 4) {
        vc = self.vc5;
    } else if (number == 5) {
        vc = self.vc6;
    } else if (number == 6) {
        vc = self.vc7;
    }
    
    [vc viewDidCurrentView];
}

@end
